﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusLib
{
    public partial class Fare_Attribute
    {
        public static Fare_Attribute ImportCSV(string line)
        {
            Fare_Attribute fa = null;
            string[] fields = line.Split(',');

            if (fields[0] != "fare_id")
            {
                fa = new Fare_Attribute();
                fa.fare_id = int.Parse(fields[0]);
                fa.price = decimal.Parse(fields[1]);
                fa.currency_type = fields[2];
                fa.payment_method = int.Parse(fields[3]);
                fa.transfers = fields[4] == "" ? null : (int?)int.Parse(fields[4]);
                fa.transfer_duration = TimeSpan.FromSeconds(int.Parse(fields[5]));
                fa.agency_id = fields[6];

                BusLibDataContext.db.Fare_Attributes.InsertOnSubmit(fa);
            }
            return fa;
        }
    }
}
